package com.room.search.web.rest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import com.room.search.IntegrationTest;
import com.room.search.domain.RoomSupportingFacilities;
import com.room.search.repository.RoomSupportingFacilitiesRepository;
import com.room.search.service.dto.RoomSupportingFacilitiesDTO;
import com.room.search.service.mapper.RoomSupportingFacilitiesMapper;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

/**
 * Integration tests for the {@link RoomSupportingFacilitiesResource} REST controller.
 */
@IntegrationTest
@AutoConfigureMockMvc
@WithMockUser
class RoomSupportingFacilitiesResourceIT {

    private static final Boolean DEFAULT_WASHER = false;
    private static final Boolean UPDATED_WASHER = true;

    private static final Boolean DEFAULT_AIR_CONDITION = false;
    private static final Boolean UPDATED_AIR_CONDITION = true;

    private static final Boolean DEFAULT_WATER_HEATER = false;
    private static final Boolean UPDATED_WATER_HEATER = true;

    private static final Boolean DEFAULT_BED = false;
    private static final Boolean UPDATED_BED = true;

    private static final Boolean DEFAULT_HEATING = false;
    private static final Boolean UPDATED_HEATING = true;

    private static final Boolean DEFAULT_WARDROBE = false;
    private static final Boolean UPDATED_WARDROBE = true;

    private static final Boolean DEFAULT_REFRIGERATOR = false;
    private static final Boolean UPDATED_REFRIGERATOR = true;

    private static final Boolean DEFAULT_NATURAL_GAS = false;
    private static final Boolean UPDATED_NATURAL_GAS = true;

    private static final Boolean DEFAULT_INTERNET = false;
    private static final Boolean UPDATED_INTERNET = true;

    private static final Boolean DEFAULT_TELEVISION = false;
    private static final Boolean UPDATED_TELEVISION = true;

    private static final String ENTITY_API_URL = "/api/room-supporting-facilities";
    private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}";

    private static Random random = new Random();
    private static AtomicLong count = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));

    @Autowired
    private RoomSupportingFacilitiesRepository roomSupportingFacilitiesRepository;

    @Autowired
    private RoomSupportingFacilitiesMapper roomSupportingFacilitiesMapper;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restRoomSupportingFacilitiesMockMvc;

    private RoomSupportingFacilities roomSupportingFacilities;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomSupportingFacilities createEntity(EntityManager em) {
        RoomSupportingFacilities roomSupportingFacilities = new RoomSupportingFacilities()
            .washer(DEFAULT_WASHER)
            .airCondition(DEFAULT_AIR_CONDITION)
            .waterHeater(DEFAULT_WATER_HEATER)
            .bed(DEFAULT_BED)
            .heating(DEFAULT_HEATING)
            .wardrobe(DEFAULT_WARDROBE)
            .refrigerator(DEFAULT_REFRIGERATOR)
            .naturalGas(DEFAULT_NATURAL_GAS)
            .internet(DEFAULT_INTERNET)
            .television(DEFAULT_TELEVISION);
        return roomSupportingFacilities;
    }

    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomSupportingFacilities createUpdatedEntity(EntityManager em) {
        RoomSupportingFacilities roomSupportingFacilities = new RoomSupportingFacilities()
            .washer(UPDATED_WASHER)
            .airCondition(UPDATED_AIR_CONDITION)
            .waterHeater(UPDATED_WATER_HEATER)
            .bed(UPDATED_BED)
            .heating(UPDATED_HEATING)
            .wardrobe(UPDATED_WARDROBE)
            .refrigerator(UPDATED_REFRIGERATOR)
            .naturalGas(UPDATED_NATURAL_GAS)
            .internet(UPDATED_INTERNET)
            .television(UPDATED_TELEVISION);
        return roomSupportingFacilities;
    }

    @BeforeEach
    public void initTest() {
        roomSupportingFacilities = createEntity(em);
    }

    @Test
    @Transactional
    void createRoomSupportingFacilities() throws Exception {
        int databaseSizeBeforeCreate = roomSupportingFacilitiesRepository.findAll().size();
        // Create the RoomSupportingFacilities
        RoomSupportingFacilitiesDTO roomSupportingFacilitiesDTO = roomSupportingFacilitiesMapper.toDto(roomSupportingFacilities);
        restRoomSupportingFacilitiesMockMvc
            .perform(
                post(ENTITY_API_URL)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomSupportingFacilitiesDTO))
            )
            .andExpect(status().isCreated());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeCreate + 1);
        RoomSupportingFacilities testRoomSupportingFacilities = roomSupportingFacilitiesList.get(roomSupportingFacilitiesList.size() - 1);
        assertThat(testRoomSupportingFacilities.getWasher()).isEqualTo(DEFAULT_WASHER);
        assertThat(testRoomSupportingFacilities.getAirCondition()).isEqualTo(DEFAULT_AIR_CONDITION);
        assertThat(testRoomSupportingFacilities.getWaterHeater()).isEqualTo(DEFAULT_WATER_HEATER);
        assertThat(testRoomSupportingFacilities.getBed()).isEqualTo(DEFAULT_BED);
        assertThat(testRoomSupportingFacilities.getHeating()).isEqualTo(DEFAULT_HEATING);
        assertThat(testRoomSupportingFacilities.getWardrobe()).isEqualTo(DEFAULT_WARDROBE);
        assertThat(testRoomSupportingFacilities.getRefrigerator()).isEqualTo(DEFAULT_REFRIGERATOR);
        assertThat(testRoomSupportingFacilities.getNaturalGas()).isEqualTo(DEFAULT_NATURAL_GAS);
        assertThat(testRoomSupportingFacilities.getInternet()).isEqualTo(DEFAULT_INTERNET);
        assertThat(testRoomSupportingFacilities.getTelevision()).isEqualTo(DEFAULT_TELEVISION);
    }

    @Test
    @Transactional
    void createRoomSupportingFacilitiesWithExistingId() throws Exception {
        // Create the RoomSupportingFacilities with an existing ID
        roomSupportingFacilities.setId(1L);
        RoomSupportingFacilitiesDTO roomSupportingFacilitiesDTO = roomSupportingFacilitiesMapper.toDto(roomSupportingFacilities);

        int databaseSizeBeforeCreate = roomSupportingFacilitiesRepository.findAll().size();

        // An entity with an existing ID cannot be created, so this API call must fail
        restRoomSupportingFacilitiesMockMvc
            .perform(
                post(ENTITY_API_URL)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomSupportingFacilitiesDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeCreate);
    }

    @Test
    @Transactional
    void getAllRoomSupportingFacilities() throws Exception {
        // Initialize the database
        roomSupportingFacilitiesRepository.saveAndFlush(roomSupportingFacilities);

        // Get all the roomSupportingFacilitiesList
        restRoomSupportingFacilitiesMockMvc
            .perform(get(ENTITY_API_URL + "?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(roomSupportingFacilities.getId().intValue())))
            .andExpect(jsonPath("$.[*].washer").value(hasItem(DEFAULT_WASHER.booleanValue())))
            .andExpect(jsonPath("$.[*].airCondition").value(hasItem(DEFAULT_AIR_CONDITION.booleanValue())))
            .andExpect(jsonPath("$.[*].waterHeater").value(hasItem(DEFAULT_WATER_HEATER.booleanValue())))
            .andExpect(jsonPath("$.[*].bed").value(hasItem(DEFAULT_BED.booleanValue())))
            .andExpect(jsonPath("$.[*].heating").value(hasItem(DEFAULT_HEATING.booleanValue())))
            .andExpect(jsonPath("$.[*].wardrobe").value(hasItem(DEFAULT_WARDROBE.booleanValue())))
            .andExpect(jsonPath("$.[*].refrigerator").value(hasItem(DEFAULT_REFRIGERATOR.booleanValue())))
            .andExpect(jsonPath("$.[*].naturalGas").value(hasItem(DEFAULT_NATURAL_GAS.booleanValue())))
            .andExpect(jsonPath("$.[*].internet").value(hasItem(DEFAULT_INTERNET.booleanValue())))
            .andExpect(jsonPath("$.[*].television").value(hasItem(DEFAULT_TELEVISION.booleanValue())));
    }

    @Test
    @Transactional
    void getRoomSupportingFacilities() throws Exception {
        // Initialize the database
        roomSupportingFacilitiesRepository.saveAndFlush(roomSupportingFacilities);

        // Get the roomSupportingFacilities
        restRoomSupportingFacilitiesMockMvc
            .perform(get(ENTITY_API_URL_ID, roomSupportingFacilities.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(roomSupportingFacilities.getId().intValue()))
            .andExpect(jsonPath("$.washer").value(DEFAULT_WASHER.booleanValue()))
            .andExpect(jsonPath("$.airCondition").value(DEFAULT_AIR_CONDITION.booleanValue()))
            .andExpect(jsonPath("$.waterHeater").value(DEFAULT_WATER_HEATER.booleanValue()))
            .andExpect(jsonPath("$.bed").value(DEFAULT_BED.booleanValue()))
            .andExpect(jsonPath("$.heating").value(DEFAULT_HEATING.booleanValue()))
            .andExpect(jsonPath("$.wardrobe").value(DEFAULT_WARDROBE.booleanValue()))
            .andExpect(jsonPath("$.refrigerator").value(DEFAULT_REFRIGERATOR.booleanValue()))
            .andExpect(jsonPath("$.naturalGas").value(DEFAULT_NATURAL_GAS.booleanValue()))
            .andExpect(jsonPath("$.internet").value(DEFAULT_INTERNET.booleanValue()))
            .andExpect(jsonPath("$.television").value(DEFAULT_TELEVISION.booleanValue()));
    }

    @Test
    @Transactional
    void getNonExistingRoomSupportingFacilities() throws Exception {
        // Get the roomSupportingFacilities
        restRoomSupportingFacilitiesMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    void putNewRoomSupportingFacilities() throws Exception {
        // Initialize the database
        roomSupportingFacilitiesRepository.saveAndFlush(roomSupportingFacilities);

        int databaseSizeBeforeUpdate = roomSupportingFacilitiesRepository.findAll().size();

        // Update the roomSupportingFacilities
        RoomSupportingFacilities updatedRoomSupportingFacilities = roomSupportingFacilitiesRepository
            .findById(roomSupportingFacilities.getId())
            .get();
        // Disconnect from session so that the updates on updatedRoomSupportingFacilities are not directly saved in db
        em.detach(updatedRoomSupportingFacilities);
        updatedRoomSupportingFacilities
            .washer(UPDATED_WASHER)
            .airCondition(UPDATED_AIR_CONDITION)
            .waterHeater(UPDATED_WATER_HEATER)
            .bed(UPDATED_BED)
            .heating(UPDATED_HEATING)
            .wardrobe(UPDATED_WARDROBE)
            .refrigerator(UPDATED_REFRIGERATOR)
            .naturalGas(UPDATED_NATURAL_GAS)
            .internet(UPDATED_INTERNET)
            .television(UPDATED_TELEVISION);
        RoomSupportingFacilitiesDTO roomSupportingFacilitiesDTO = roomSupportingFacilitiesMapper.toDto(updatedRoomSupportingFacilities);

        restRoomSupportingFacilitiesMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomSupportingFacilitiesDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomSupportingFacilitiesDTO))
            )
            .andExpect(status().isOk());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeUpdate);
        RoomSupportingFacilities testRoomSupportingFacilities = roomSupportingFacilitiesList.get(roomSupportingFacilitiesList.size() - 1);
        assertThat(testRoomSupportingFacilities.getWasher()).isEqualTo(UPDATED_WASHER);
        assertThat(testRoomSupportingFacilities.getAirCondition()).isEqualTo(UPDATED_AIR_CONDITION);
        assertThat(testRoomSupportingFacilities.getWaterHeater()).isEqualTo(UPDATED_WATER_HEATER);
        assertThat(testRoomSupportingFacilities.getBed()).isEqualTo(UPDATED_BED);
        assertThat(testRoomSupportingFacilities.getHeating()).isEqualTo(UPDATED_HEATING);
        assertThat(testRoomSupportingFacilities.getWardrobe()).isEqualTo(UPDATED_WARDROBE);
        assertThat(testRoomSupportingFacilities.getRefrigerator()).isEqualTo(UPDATED_REFRIGERATOR);
        assertThat(testRoomSupportingFacilities.getNaturalGas()).isEqualTo(UPDATED_NATURAL_GAS);
        assertThat(testRoomSupportingFacilities.getInternet()).isEqualTo(UPDATED_INTERNET);
        assertThat(testRoomSupportingFacilities.getTelevision()).isEqualTo(UPDATED_TELEVISION);
    }

    @Test
    @Transactional
    void putNonExistingRoomSupportingFacilities() throws Exception {
        int databaseSizeBeforeUpdate = roomSupportingFacilitiesRepository.findAll().size();
        roomSupportingFacilities.setId(count.incrementAndGet());

        // Create the RoomSupportingFacilities
        RoomSupportingFacilitiesDTO roomSupportingFacilitiesDTO = roomSupportingFacilitiesMapper.toDto(roomSupportingFacilities);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomSupportingFacilitiesMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomSupportingFacilitiesDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomSupportingFacilitiesDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithIdMismatchRoomSupportingFacilities() throws Exception {
        int databaseSizeBeforeUpdate = roomSupportingFacilitiesRepository.findAll().size();
        roomSupportingFacilities.setId(count.incrementAndGet());

        // Create the RoomSupportingFacilities
        RoomSupportingFacilitiesDTO roomSupportingFacilitiesDTO = roomSupportingFacilitiesMapper.toDto(roomSupportingFacilities);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomSupportingFacilitiesMockMvc
            .perform(
                put(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomSupportingFacilitiesDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithMissingIdPathParamRoomSupportingFacilities() throws Exception {
        int databaseSizeBeforeUpdate = roomSupportingFacilitiesRepository.findAll().size();
        roomSupportingFacilities.setId(count.incrementAndGet());

        // Create the RoomSupportingFacilities
        RoomSupportingFacilitiesDTO roomSupportingFacilitiesDTO = roomSupportingFacilitiesMapper.toDto(roomSupportingFacilities);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomSupportingFacilitiesMockMvc
            .perform(
                put(ENTITY_API_URL)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomSupportingFacilitiesDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void partialUpdateRoomSupportingFacilitiesWithPatch() throws Exception {
        // Initialize the database
        roomSupportingFacilitiesRepository.saveAndFlush(roomSupportingFacilities);

        int databaseSizeBeforeUpdate = roomSupportingFacilitiesRepository.findAll().size();

        // Update the roomSupportingFacilities using partial update
        RoomSupportingFacilities partialUpdatedRoomSupportingFacilities = new RoomSupportingFacilities();
        partialUpdatedRoomSupportingFacilities.setId(roomSupportingFacilities.getId());

        partialUpdatedRoomSupportingFacilities
            .airCondition(UPDATED_AIR_CONDITION)
            .refrigerator(UPDATED_REFRIGERATOR)
            .internet(UPDATED_INTERNET)
            .television(UPDATED_TELEVISION);

        restRoomSupportingFacilitiesMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomSupportingFacilities.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomSupportingFacilities))
            )
            .andExpect(status().isOk());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeUpdate);
        RoomSupportingFacilities testRoomSupportingFacilities = roomSupportingFacilitiesList.get(roomSupportingFacilitiesList.size() - 1);
        assertThat(testRoomSupportingFacilities.getWasher()).isEqualTo(DEFAULT_WASHER);
        assertThat(testRoomSupportingFacilities.getAirCondition()).isEqualTo(UPDATED_AIR_CONDITION);
        assertThat(testRoomSupportingFacilities.getWaterHeater()).isEqualTo(DEFAULT_WATER_HEATER);
        assertThat(testRoomSupportingFacilities.getBed()).isEqualTo(DEFAULT_BED);
        assertThat(testRoomSupportingFacilities.getHeating()).isEqualTo(DEFAULT_HEATING);
        assertThat(testRoomSupportingFacilities.getWardrobe()).isEqualTo(DEFAULT_WARDROBE);
        assertThat(testRoomSupportingFacilities.getRefrigerator()).isEqualTo(UPDATED_REFRIGERATOR);
        assertThat(testRoomSupportingFacilities.getNaturalGas()).isEqualTo(DEFAULT_NATURAL_GAS);
        assertThat(testRoomSupportingFacilities.getInternet()).isEqualTo(UPDATED_INTERNET);
        assertThat(testRoomSupportingFacilities.getTelevision()).isEqualTo(UPDATED_TELEVISION);
    }

    @Test
    @Transactional
    void fullUpdateRoomSupportingFacilitiesWithPatch() throws Exception {
        // Initialize the database
        roomSupportingFacilitiesRepository.saveAndFlush(roomSupportingFacilities);

        int databaseSizeBeforeUpdate = roomSupportingFacilitiesRepository.findAll().size();

        // Update the roomSupportingFacilities using partial update
        RoomSupportingFacilities partialUpdatedRoomSupportingFacilities = new RoomSupportingFacilities();
        partialUpdatedRoomSupportingFacilities.setId(roomSupportingFacilities.getId());

        partialUpdatedRoomSupportingFacilities
            .washer(UPDATED_WASHER)
            .airCondition(UPDATED_AIR_CONDITION)
            .waterHeater(UPDATED_WATER_HEATER)
            .bed(UPDATED_BED)
            .heating(UPDATED_HEATING)
            .wardrobe(UPDATED_WARDROBE)
            .refrigerator(UPDATED_REFRIGERATOR)
            .naturalGas(UPDATED_NATURAL_GAS)
            .internet(UPDATED_INTERNET)
            .television(UPDATED_TELEVISION);

        restRoomSupportingFacilitiesMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomSupportingFacilities.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomSupportingFacilities))
            )
            .andExpect(status().isOk());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeUpdate);
        RoomSupportingFacilities testRoomSupportingFacilities = roomSupportingFacilitiesList.get(roomSupportingFacilitiesList.size() - 1);
        assertThat(testRoomSupportingFacilities.getWasher()).isEqualTo(UPDATED_WASHER);
        assertThat(testRoomSupportingFacilities.getAirCondition()).isEqualTo(UPDATED_AIR_CONDITION);
        assertThat(testRoomSupportingFacilities.getWaterHeater()).isEqualTo(UPDATED_WATER_HEATER);
        assertThat(testRoomSupportingFacilities.getBed()).isEqualTo(UPDATED_BED);
        assertThat(testRoomSupportingFacilities.getHeating()).isEqualTo(UPDATED_HEATING);
        assertThat(testRoomSupportingFacilities.getWardrobe()).isEqualTo(UPDATED_WARDROBE);
        assertThat(testRoomSupportingFacilities.getRefrigerator()).isEqualTo(UPDATED_REFRIGERATOR);
        assertThat(testRoomSupportingFacilities.getNaturalGas()).isEqualTo(UPDATED_NATURAL_GAS);
        assertThat(testRoomSupportingFacilities.getInternet()).isEqualTo(UPDATED_INTERNET);
        assertThat(testRoomSupportingFacilities.getTelevision()).isEqualTo(UPDATED_TELEVISION);
    }

    @Test
    @Transactional
    void patchNonExistingRoomSupportingFacilities() throws Exception {
        int databaseSizeBeforeUpdate = roomSupportingFacilitiesRepository.findAll().size();
        roomSupportingFacilities.setId(count.incrementAndGet());

        // Create the RoomSupportingFacilities
        RoomSupportingFacilitiesDTO roomSupportingFacilitiesDTO = roomSupportingFacilitiesMapper.toDto(roomSupportingFacilities);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomSupportingFacilitiesMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, roomSupportingFacilitiesDTO.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomSupportingFacilitiesDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithIdMismatchRoomSupportingFacilities() throws Exception {
        int databaseSizeBeforeUpdate = roomSupportingFacilitiesRepository.findAll().size();
        roomSupportingFacilities.setId(count.incrementAndGet());

        // Create the RoomSupportingFacilities
        RoomSupportingFacilitiesDTO roomSupportingFacilitiesDTO = roomSupportingFacilitiesMapper.toDto(roomSupportingFacilities);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomSupportingFacilitiesMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomSupportingFacilitiesDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithMissingIdPathParamRoomSupportingFacilities() throws Exception {
        int databaseSizeBeforeUpdate = roomSupportingFacilitiesRepository.findAll().size();
        roomSupportingFacilities.setId(count.incrementAndGet());

        // Create the RoomSupportingFacilities
        RoomSupportingFacilitiesDTO roomSupportingFacilitiesDTO = roomSupportingFacilitiesMapper.toDto(roomSupportingFacilities);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomSupportingFacilitiesMockMvc
            .perform(
                patch(ENTITY_API_URL)
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomSupportingFacilitiesDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomSupportingFacilities in the database
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void deleteRoomSupportingFacilities() throws Exception {
        // Initialize the database
        roomSupportingFacilitiesRepository.saveAndFlush(roomSupportingFacilities);

        int databaseSizeBeforeDelete = roomSupportingFacilitiesRepository.findAll().size();

        // Delete the roomSupportingFacilities
        restRoomSupportingFacilitiesMockMvc
            .perform(delete(ENTITY_API_URL_ID, roomSupportingFacilities.getId()).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<RoomSupportingFacilities> roomSupportingFacilitiesList = roomSupportingFacilitiesRepository.findAll();
        assertThat(roomSupportingFacilitiesList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
